from re import S, T
from numpy import square
from manimlib import *
#75cfb8
#bbdfc8
#f0e5d8
#ffc478
class p1(Scene):
    def construct(self):
        # self.add(NumberPlane())
        frame = self.camera.frame
        side=3*np.sqrt(17)+3
        half=side/2
        a,b,c,d=[-half,half,0],[half,half,0],[half,-half,0],[-half,-half,0]
        self.play(frame.animate.set_width(32))
        s=Square(side)
        o1=[-(side/2-6),side/2,0]
        s1=Sector(PI,PI,outer_radius=6,arc_center=o1).set_fill('#75cfb8',1)
        o2=[side/2,-side/2,0]
        s2=Sector(PI/2,PI/2,outer_radius=12,arc_center=o2).set_fill('#ffc478',1)
        self.add(s2,s1,s,Tex('A').next_to(a,UL),Tex('B').next_to(b,UR),Tex('C').next_to(c,DR),Tex('D').next_to(d,DL))
        #
        b1=Brace(Line(o1+LEFT*6,o1+RIGHT*6),UP)
        b2=Brace(Line(o2,o2+UP*12),RIGHT)
        t1=Tex('12').next_to(b1,UP)
        t2=Tex('12').next_to(b2,RIGHT)
        self.add(b1,b2,t1,t2)
        #
        bb=Brace(Line(o1+RIGHT*6,o2+UP*side),UP,color=RED)
        tb=Tex('x=?',color=RED).next_to(bb,UP)
        self.add(bb,tb)
        self.wait()
class p2(Scene):
    def construct(self):
        # self.add(NumberPlane())
        frame = self.camera.frame
        side=3*np.sqrt(17)+3
        half=side/2
        a,b,c,d=[-half,half,0],[half,half,0],[half,-half,0],[-half,-half,0]
        self.play(frame.animate.set_width(32))
        s=Square(side)
        o1=[-(side/2-6),side/2,0]
        s1=Sector(PI,PI,outer_radius=6,arc_center=o1).set_fill('#75cfb8',1)
        o2=[side/2,-side/2,0]
        s2=Sector(PI/2,PI/2,outer_radius=12,arc_center=o2).set_fill('#ffc478',1)
        self.add(s2,s1,s,Tex('A').next_to(a,UL),Tex('B').next_to(b,UR),Tex('C').next_to(c,DR),Tex('D').next_to(d,DL))
        #
        b1=Brace(Line(o1+LEFT*6,o1+RIGHT*6),UP)
        b2=Brace(Line(o2,o2+UP*12),RIGHT)
        t1=Tex('12').next_to(b1,UP)
        t2=Tex('12').next_to(b2,RIGHT)
        self.add(b1,b2,t1,t2)
        #
        bb=Brace(Line(o1+RIGHT*6,o2+UP*side),UP,color=RED)
        tb=Tex('x=?',color=RED).next_to(bb,UP)
        self.add(bb,tb,Tex('O').next_to(o1,DOWN),Line(o1,c),Tex('P').shift(UR))
        self.wait()
class p3(Scene):
    def construct(self):
        # self.add(NumberPlane())
        frame = self.camera.frame
        side=3*np.sqrt(17)+3
        half=side/2
        a,b,c,d=[-half,half,0],[half,half,0],[half,-half,0],[-half,-half,0]
        self.play(frame.animate.set_width(32))
        s=Square(side)
        o1=[-(side/2-6),side/2,0]
        s1=Sector(PI,PI,outer_radius=6,arc_center=o1).set_fill('#75cfb8',1)
        o2=[side/2,-side/2,0]
        s2=Sector(PI/2,PI/2,outer_radius=12,arc_center=o2).set_fill('#ffc478',1)
        self.add(s2,s1,s,Tex('A').next_to(a,UL),Tex('B').next_to(b,UR),Tex('C').next_to(c,DR),Tex('D').next_to(d,DL))
        #
        b1=Brace(Line(o1+LEFT*6,o1+RIGHT*6),UP)
        b2=Brace(Line(o2,o2+UP*12),RIGHT)
        t1=Tex('12').next_to(b1,UP)
        t2=Tex('12').next_to(b2,RIGHT)
        self.add(b1,b2,t1,t2)
        #
        m=[-7.68,-3,0]
        n=[7.68,6.37,0]
        mn=Line(m,n)
        tm=Tex('M').next_to(m,LEFT)
        tn=Tex('N').next_to(n,RIGHT)
        self.add(mn,tm,tn,Text('切线MN=?',color=RED).shift(LEFT*5))
        self.wait()
class p4(Scene):
    def construct(self):
        # self.add(NumberPlane())
        frame = self.camera.frame
        side=3*np.sqrt(17)+3
        half=side/2
        a,b,c,d=[-half,half,0],[half,half,0],[half,-half,0],[-half,-half,0]
        self.play(frame.animate.set_width(32))
        s=Square(side)
        o1=[-(side/2-6),side/2,0]
        s1=Sector(PI,PI,outer_radius=6,arc_center=o1).set_fill('#75cfb8',1)
        o2=[side/2,-side/2,0]
        s2=Sector(PI/2,PI/2,outer_radius=12,arc_center=o2).set_fill('#ffc478',1)
        self.add(s2,s1,s,Tex('A').next_to(a,UL),Tex('B').next_to(b,UR),Tex('C').next_to(c,DR),Tex('D').next_to(d,DL))
        #
        b1=Brace(Line(o1+LEFT*6,o1+RIGHT*6),UP)
        b2=Brace(Line(o2,o2+UP*12),RIGHT)
        t1=Tex('12').next_to(b1,UP)
        t2=Tex('12').next_to(b2,RIGHT)
        self.add(b1,b2,t1,t2)
        #
        m=[-7.68,-3,0]
        n=[7.68,6.37,0]
        mn=Line(m,n)
        tm=Tex('M').next_to(m,LEFT)
        tn=Tex('N').next_to(n,RIGHT)
        self.add(mn,tm,tn,Text('切线MN=?',color=RED).shift(LEFT*5))
        #
        q=m+RIGHT*side
        self.add(Tex('O').next_to(o1,DOWN),Line(o1,c),Tex('P').shift(UR),Line(m,q),Tex('Q').next_to(q,RIGHT,buff=0.4))

        self.wait()